<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/10
 * Time: 13:13
 */

namespace app\admin\controller;

use app\admin\model\CategoryList as CategoryListModel;
use app\admin\model\CategoryList;
use app\admin\model\CategoryTitle;
use app\admin\model\CategoryTitle as CategoryTitleModel;
use app\admin\model\CategoryTitleRoom as CategoryTitleRoomModel;
class LabelCategory extends Index
{

    public function categoryIndex()
    {
        return view();
    }

    public function CategoryIndexData()
    {
        $categoryListModel = new CategoryListModel();
        $data = $categoryListModel->CategoryIndexData();
        return json($data);
    }

    public function categoryChangeStatus()
    {
        $categoryListModel = new CategoryListModel();
        $res = $categoryListModel->categoryChangeStatus();
        return $res;
    }
    public function categoryEdit()
    {
        $id = input('get.id');
        $sort = input('get.sort');
        $res = CategoryList::where('id','eq',$id)->update(['sort'=> $sort]);
        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else return ['code'=>-100,'msg'=>'修改失败'];
    }



    public function categoryAdd()
    {
        $categoryListModel = new CategoryListModel();
        $res = $categoryListModel->categoryAdd();
        if($res['code'] == 100) $this->success($res['msg']);
        else $this->error($res['msg']);

    }

    public function labelIndex()
    {
        $data = CategoryList::field('id,name')->select()->toArray();
        return view()->assign('data',$data);
    }

    public function labelIndexData()
    {
        $categoryTitleModel = new CategoryTitleModel();
        $data = $categoryTitleModel->labelIndexData();
        return json($data);
    }

    public function labelChangeStatus()
    {
        $categoryTitleModel = new CategoryTitleModel();
        $res = $categoryTitleModel->labelChangeStatus();
        return $res;
    }

    public function labelAdd()
    {
        $categoryTitleModel = new CategoryTitleModel();
        $res = $categoryTitleModel->labelAdd();
        if($res['code'] == 100) $this->success($res['msg']);
        else $this->error($res['msg']);
    }

    public function labelRoom()
    {
        $categoryTitleRoomModel = new CategoryTitleRoomModel();
        $data = $categoryTitleRoomModel->labelRoom();
        return view()->assign('data',$data);
    }

    public function labelRoomAdd()
    {
        $title_id = input('get.title_id');
        $u_id = input('get.u_id');
        if($u_id){
            $categoryTitleRoomModel = new CategoryTitleRoomModel();
            $res = $categoryTitleRoomModel->labelRoomAdd($u_id,$title_id);
            return $res;
        }
        return view()->assign('title_id',$title_id);
    }

    public function labelEdit()
    {
        $id = input('get.id');
        $sort = input('get.sort');
        $res = CategoryTitle::where('id','eq',$id)->update(['sort'=> $sort]);
        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else return ['code'=>-100,'msg'=>'修改失败'];
    }

    public function labelRoomChangeStatus()
    {
        $categoryTitleRoomModel = new CategoryTitleRoomModel();
        $res = $categoryTitleRoomModel->labelRoomChangeStatus();
        return $res;
    }




}